package dto.avonigo.com;

import java.util.Date;

import javax.jdo.PersistenceManager;

import model.avonigo.com.User;

public class UserDTO {

	PersistenceManager pm = PMF.get().getPersistenceManager();
	
	public void saveUser(User user){
		User e = new User(user.getFirstName(), user.getLastName(), user.getMail(), new Date(), user.getServerName(), user.getServerAdresse(), user.getLocation());
        try {
            pm.makePersistent(e);
        } finally {
            pm.close();
        }
	}
	
	public User getUserByMail(User user) {
	    PersistenceManager pm = PMF.get().getPersistenceManager();
	    User e, detached = null;
	    try {
	        e = pm.getObjectById(User.class,
	            user.getMail());

	        // If you're using transactions, you can call
	        // pm.setDetachAllOnCommit(true) before committing to automatically
	        // detach all objects without calls to detachCopy or detachCopyAll.
	        detached = pm.detachCopy(e);
	    } finally {
	        pm.close();
	    }
	    return detached;
	}
}
